#!/bin/bash

echo "########## 安装开始.. 根据节点修改 VAR_HOSTNAME"
VAR_HOSTNAME="k8s-master"






echo "########## 配置yum源"
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
wget -O /etc/yum.repos.d/CentOS7.aliyun.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/docker-ce.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
yum clean all && yum makecache





echo "########## 修改内核参数"
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
sysctl --system
modprobe br_netfilter





echo "########## 安装dokcer与k8s"
yum install -y yum-utils device-mapper-persistent-data lvm2
yum install -y docker-ce-20.10.7-3.el7
yum install -y kubelet-1.23.6 kubeadm-1.23.6 kubectl-1.23.6

echo "########## 配置docker"
cat > /etc/docker/daemon.json << EOF
{
  "registry-mirrors": [
        "https://hnkfbj7x.mirror.aliyuncs.com",
        "http://hub-mirror.c.163.com",
        "https://docker.mirrors.ustc.edu.cn",
        "https://docker.m.daocloud.io",
        "https://docker.unsee.tech",
        "https://docker.1panel.live",
        "https://proxy.1panel.live",
        "http://mirrors.ustc.edu.cn",
        "http://mirror.azure.cn",
        "https://dockerpull.org",
        "https://dockerhub.icu",
        "https://hub.rat.dev",
        "https://docker.chenby.cn",
        "https://docker.ketches.cn",
        "https://docker.awsl9527.cn",
        "https://atomhub.openatom.cn",
        "https://register.librax.org"
  ],
  "exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
systemctl daemon-reload
systemctl restart docker
systemctl restart kubelet
systemctl enable docker
systemctl enable kubelet
